package com.baymax.springboot.cli.aware;

import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author xiao.hu
 * @date 2021-08-19
 * @apiNote
 */
@Component
public class ProfileUtil implements ApplicationContextAware {

    private static ApplicationContext context = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        context = applicationContext;
    }

    /**
     *
     * @return
     */
    public static String getActiveProfile() {
        String []profiles = context.getEnvironment().getActiveProfiles();
        if(!ArrayUtils.isEmpty(profiles)){
            return profiles[0];
        }
        return "";
    }
}
